import { createRouter, createWebHistory } from 'vue-router';
import index from '@/views/index.vue';
import indexVue from '@/views/index/index.vue';
import AboutVue from '@/views/about/About.vue';
import ContantVue from '@/views/index/Contant.vue';
 //公司业务
import ShuangqinChildren from './business/shuangqing.js'; // 导入业务路由的 children
import BaiguanChildren from './business/baiguan.js'; // 导入业务路由的 children
import TransportationLineChildren from './business/transportationLine.js'; //
import CustomsChildren from './business/customs';
//用户业务
import UserIndex from '@/usersViews/index.vue';
import UserIndexVue from '@/usersViews/index/index.vue';
import UaboutVue from '@/usersViews/about/About.vue';
import UContantVue from '@/usersViews/index/Contant.vue';
/*用户子路由*/
import UNewChildren from './urouter/new/new.js';
import UCaseChildren from './urouter/case/case.js';
/*用户生意子路由*/
import UShuangqinChildren from './urouter/business/shuangqing.js';
import UBaiguanChildren from './urouter/business/baiguan.js';
import UTransportationLineChildren from './urouter/business/transportationLine.js';
import UCustomsChildren from './urouter/business/customs.js';
/*用户server子路由*/
import UServiceChildren from './urouter/service/service.js';
/*用户展会子路由*/
import UExhibitionChildren from './urouter/exhibition/exhibition.js';


import ServiceChildren from './service/service.js';
import ExhibitionChildren from './exhibition/exhibition.js';
import NewChildren from './new/new.js';
import CaseChildren from './case/case.js';
const routes = [
  {
    path: '/admin',
    name: 'index',
    component: index,
    children: [
      {
        path: '/admin', // 这个空路径会匹配父路由的路径 /
        name: 'indexVue',
        component: indexVue,
      },
      {
        path: 'business', // 这里是子路由的路径，访问 /business 将渲染 Business 组件
        name: 'business',
        children: [
          {
            path: 'shuangqing',
            name: 'shuangqing',
            children: ShuangqinChildren
          },
          {
            path: 'baiguan',
            name: 'baiguan',
            children: BaiguanChildren
          },
          {
            path: 'transportation',
            name: 'transportation',
            children: TransportationLineChildren
          },
          {
            path: 'customs',
            name: 'customs',
            children: CustomsChildren
          },
        ]
      },
      {
        path: 'service',
        name: 'service',
        //component: ServiceVue,
        children: ServiceChildren
      },
      {
        path: 'about',
        name: 'about',
        component: AboutVue,
      },
      {
        path: 'contant',
        name: 'contant',
        component: ContantVue,
      },
      {
        path: 'exhibition',
        name: 'exhibition',
        children: ExhibitionChildren
      },
      {
        path: 'new',
        name: 'new',
        children: NewChildren
      },
      {
        path: 'case',
        name: 'case',
        children: CaseChildren
      },
      {
        path: 'message',
        name: 'Message',
        component: () => import('@/views/index/Message.vue')
      }

    ],
  },
  {
    path: '/',
    name: 'UserIndex',
    component: UserIndex,
    children: [
      {
        path: '', // 这个空路径会匹配父路由的路径 /
        name: 'UserIndexVue',
        component: UserIndexVue,
      },
      {
        path: 'business', // 这里是子路由的路径，访问 /business 将渲染 Business 组件
        name: 'Ubusiness',
        //component: BusinessVue,
        children: [
          {
            path: 'shuangqing',
            name: 'Ushuangqing',
            children: UShuangqinChildren
          },
          {
            path: 'baiguan',
            name: 'Ubaiguan',
            children: UBaiguanChildren
          },
          {
            path: 'transportation',
            name: 'Utransportation',
            children: UTransportationLineChildren
          },
          {
            path: 'customs',
            name: 'Ucustoms',
            children: UCustomsChildren
          },
        ]
      },
      {
        path: 'service',
        name: 'Uservice',
        //component: ServiceVue,
        children: UServiceChildren
      },
      {
        path: 'about',
        name: 'Userabout',
        component: UaboutVue,
      },
      {
        path: 'contant',
        name: 'Ucontant',
        component: UContantVue,
      },
      {
        path: 'exhibition',
        name: 'Uexhibition',
        //component: ExhibitionVue,
        children: UExhibitionChildren
      },
      {
        path: 'new',
        name: 'Unew',
        //component: NewVue,
        children: UNewChildren
      },
      {
        path: 'case',
        name: 'Ucase',
        children: UCaseChildren
      },

    ],
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    console.log('Saved Position:', savedPosition);
    // 在这里判断特定的路由
    if (to.name === 'caseVue' || to.name === 'UnewVue'|| to.name === 'ucaseVue'|| to.name === 'newVue') {
      console.log('Navigating to(if):', to.name);
      console.log('Saved Position:', savedPosition);
      if (savedPosition) {
        return savedPosition;
      } else {
        return { top: 0 };
      }
    } else {
      console.log('Navigating to(else):', to.name);
      console.log('Saved Position:', savedPosition);
      // 对于其他路由，返回到固定位置（比如顶部）
      return { top: 0};
    }
  }
/*  scrollBehavior(to, from, savedPosition) {
    console.log(savedPosition);
    return  savedPosition ; // 每次导航都滚动到顶部
  },*/


});

export default router;
